﻿using AntdUI;
using Super.Admin.Entities;
using Super.Admin.Models.Role;

namespace Super.Admin.Mappers
{
    /// <summary>
    /// RoleMapper 类用于在 RoleEntity 和 RoleModel 之间进行转换。
    /// </summary>
    public static class RoleMapper
    {
        /// <summary>
        /// 将 RoleEntity 转换为 RoleBaseModel。
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public static RoleBaseModel ToBaseModel(this RoleEntity entity)
        {
            if (entity == null) return null;
            return new RoleBaseModel
            {
                Id = entity.Id,
                Name = entity.Name,
                IsActive = entity.IsActive,
                CreateTime = entity.CreateTime,
                Remark = entity.Remark,
                UpdateTime = entity.UpdateTime,
                IsActiveTag = entity.IsActive == 0 ? new CellTag[] { new CellTag("启用", TTypeMini.Success) } : entity.IsActive == 1 ? new CellTag[] { new CellTag("停用", TTypeMini.Error) } : new CellTag[] { new CellTag("未知", TTypeMini.Default) },
            };
        }
        /// <summary>
        /// 将 RoleBaseModel 转换为 RoleEntity。
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static RoleEntity ToEntity(this RoleBaseModel model)
        {
            if (model == null) return null;
            return new RoleEntity
            {
                Id = model.Id,
                Name = model.Name,
                IsActive = model.IsActive,
                CreateTime = model.CreateTime,
                Remark = model.Remark,
                UpdateTime = model.UpdateTime,
            };
        }
        /// <summary>
        /// 将 RoleEntity 的集合转换为 RoleBaseModel 的集合。
        /// </summary>
        /// <param name="entities"></param>
        /// <returns></returns>
        public static IEnumerable<RoleBaseModel> ToBaseModels(this IEnumerable<RoleEntity> entities)
        {
            return entities?.Select(e => e.ToBaseModel()).ToList();
        }
        /// <summary>
        /// 将 RoleBaseModel 的集合转换为 RoleEntity 的集合。
        /// </summary>
        /// <param name="models"></param>
        /// <returns></returns>
        public static IEnumerable<RoleEntity> ToEntities(this IEnumerable<RoleBaseModel> models)
        {
            return models?.Select(m => m.ToEntity()).ToList();
        }
    }
}
